import requests
from bs4 import BeautifulSoup as bs
#请求页面方法
def getPage():
    url="http://data.sports.sohu.com/nba/nba_players_rank.php?order_by=points&spm=smpc.fb-nba-home.top-dc.2.1620824904040nf6byr7"
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'}
    resp = requests.get(url=url,headers=headers)
    resp.encoding = 'utf-8'
    page_text = resp.text
    return page_text
   

def parsePage(page_text):
    content_list = []
    soup = bs(page_text,'lxml')
    fo = open('player.json','w',encoding = 'utf-8')
    tr_list = soup.select('.table01 > tr ')
    for tr in tr_list:
        content_list.append(tr.text)
    fo.writelines(content_list)
    fo.close()
if __name__ == '__main__':
    page_text=getPage()
    parsePage(page_text)
